#ifndef SERVERHANDLER_H
#define SERVERHANDLER_H

#include "../common/handler.h"

#include <QMap>

class Socket;

//服务器策略类
class ServerHandler : public Handler
{
public:
    ServerHandler(Socket* socket);

    void reset();
};

//服务器策略接口
class ServerIHandler : public IHandler
{
public:
    ServerIHandler(Socket* socket) : socket(socket) {}

protected:
    Socket* socket; // 依赖Client，用于发送数据
};

// 服务器注册策略
class ServerHandlerRegister : public ServerIHandler
{
public:
    ServerHandlerRegister(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};

// 服务器登录策略
class ServerHandlerLogin : public ServerIHandler
{
public:
    struct ServerLoginManager{
        QMap<QString, Socket*> loginManager;
    };

    ServerHandlerLogin(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
    virtual void reset() override;

private:
    QString u;
};

// 服务器聊天策略
class ServerHandlerChat : public ServerIHandler
{
public:
    ServerHandlerChat(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};

//服务器创建房间策略
class ServerHandlerCreateRoom : public ServerIHandler
{
public:
    ServerHandlerCreateRoom(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};

//服务器加入房间策略
class ServerHandlerJoinRoom : public ServerIHandler
{
public:
    ServerHandlerJoinRoom(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};

//服务器关闭房间策略
class ServerHandlerCloseRoom : public ServerIHandler
{
public:
    ServerHandlerCloseRoom(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
    static void closeroom(QString& username, QString& roomid,Socket* socket);
};

//服务器获取房间策略
class ServerHandlerGetRoom : public ServerIHandler
{
public:
    ServerHandlerGetRoom(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};

//服务器传输音频策略
class ServerHandlerAudioTrans : public ServerIHandler
{
public:
    ServerHandlerAudioTrans(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};

//服务器传输视频策略
class ServerHandlerVideoTrans : public ServerIHandler
{
public:
    ServerHandlerVideoTrans(Socket* socket) : ServerIHandler(socket) {}
    virtual void handle(const QByteArray& data) override;
};


#endif // SERVERHANDLER_H
